<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/easyui/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/easyui/locale/easyui-lang-zh_CN.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>请假管理</title>
</head>
<body>
<table id="leaveTable" fit="true"></table>
<div id="tb">
	<a class="easyui-linkbutton" iconCls="icon-add" onclick="addLeave()" plain="true">新增请假单</a>
</div>

<div id="addLeaveDialog">
	<form id="addLeaveForm" method="post">
		<table align="center" cellspacing="5px"  cellpadding="6px" style="margin-top: 15px;">
			<tr >
				<td >请假天数: </td>
				<td>
					<input type="text" id="leaveDay" name="leaveDay" >
					<span style="color: red">*</span>
				</td>
			</tr>
			<tr>
				<td  valign="top">请假原因:</td>
				<td>
					<textarea id="leaveReason" name="leaveReason"  rows="5" cols="49" style="resize:none" ></textarea>
					<span style="color: red">*</span>
				</td>
			</tr>
		</table>
	</form>
</div>
<div id="tt">
	<a class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="save()">保存</a>
	<a class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="cancel()">取消</a>
</div>
</body>
<script type="text/javascript">
$(function(){
	$("#leaveTable").datagrid({
		url:"${pageContext.request.contextPath}/getLeaveByPage",
		title:"请假管理",
		toolbar:"#tb",
		fitColumns:true,
		rownumbers:true,
		pagination:true,
		singleSelect:true,
		columns:[[
			{field:'ck',checkbox:"true"},
			{field:"leaveId",title:"编号",width:2,align:"center"},
			{field:"leaveTime",title:"请假日期",width:3,align:"center"},
			{field:"leaveDay",title:"请假天数",width:2,align:"center"},
			{field:"leaveReason",title:"请假原因",width:10,align:"center"},
			{field:"leaveState",title:"审批状态",width:3,align:"center"},
			{field:"leaveOperation",title:"操作",width:3,align:"center",formatter:leaveOperation},
		]]
		
	})
	
	$("#addLeaveDialog").dialog({
			title:"请假单",
			width:600,
			height:350,
			buttons:"#tt",
			closed:true
		})
})
	function addLeave(){
		$("#addLeaveForm").form("clear");
		$("#addLeaveDialog").dialog("open");
	}

	function cancel(){
		$("#addLeaveDialog").dialog("close");
	}

	function save(){
		var re = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/ 
    	if($("#leaveDay").val()==""){
    		$.messager.alert("警告","请输入请假天数!","info");
    		return false;
    	}else if(!re.test($("#leaveDay").val())){
    		$.messager.alert("警告","请输入数字!","info");
	 		$("#leaveDay").val("");
	 		return false;
    	}else if($("#leaveReason").val()==""){
    		$.messager.alert("警告","请输入请假原因!","info");
    		return false;
    	}
    	$.messager.confirm('确认提交', '确定要提交请假单吗?', function(r){
    		if (r){
    			$("#addLeaveForm").form("submit",{
    			    url:"${pageContext.request.contextPath}/addLeave",    
    			    success:function(data){  
    			    	if(data=="success"){
    			    		$.messager.alert("","保存成功!","info",function(){
    			    			$("#addLeaveDialog").dialog("close");
    			    			$("#leaveTable").datagrid("load");
    			    		});
    			    	}else{
    			    		$.messager.alert("提示","保存失败!","info");
    			    	}
    			    }    
    			})
    		}
    	});
		
	}

function leaveOperation(value,row){
	if(row.leaveState=='未提交'){
		return "<a href='javascript:startApply("+row.leaveId+")'>提交申请</a>";
	}else if(row.leaveState=='审核通过' || row.leaveState=='审核未通过' ||row.leaveState == "审核中"){
		return "<a href='javascript:openListCommentDialog("+row.leaveProcessinstanceid+")'>查看历史批注</a>";
	}	
}

function startApply(id){
	$.ajax({
		async:true,
		url:"${pageContext.request.contextPath}/startAppley",
		type:"post",
		data:{
			id:id
		},
		success:function(data){
			if(data == "success"){
				$.messager.alert("","提交成功，请耐心等待审核!","info",function(){
					$("#leaveTable").datagrid("load");
	    		});
			}else{
				$.messager.alert("","提交失败，请联系管理员查看原因!","info");
			}
		}
	})
	   
	
	
	
	
	
	
	
}





</script>
</html>